package org.pucc.handle

import org.pucc.bean.ImportConfig
import org.pucc.common.ClusterConstant

/** ---- ----   ---- ----    ---- ---- */
/** ---- ----   Hudi_DDL   ---- ---- */

/** ---- ----   ---- ----   ---- ---- */

object HudiHandle {

  def getHudiDatabaseDDL(importConfig: ImportConfig): String = {
    s"CREATE DATABASE IF NOT EXISTS ${importConfig.sinkDatabase}"
  }

  def getHudiTableDDL(importConfig: ImportConfig): String = {
    s"""
       |     CREATE TABLE IF NOT EXISTS ${importConfig.sinkDatabase}.${importConfig.sinkTableName} ( ${importConfig.sinkFields} )
       |      ${if (importConfig.isPartition) "PARTITIONED BY (`partition`)" else ""}
       |      WITH (
       |      'connector' = 'hudi',
       |      'path' = '${ClusterConstant.HudiMeta.DIR}/${importConfig.sinkDatabase}/${importConfig.sinkTableName}',
       |      'table.type' = 'COPY_ON_WRITE',
       |      'read.streaming.enabled' = 'true',  -- this option enable the streaming read
       |      'read.streaming.check-interval' = '30', -- specifies the check interval for finding new source commits, default 60s.
       |      'hive_sync.enable'='true',           -- required，开启hive同步功能
       |      'hive_sync.table'='${importConfig.sinkTableName}',              -- required, hive 新建的表名
       |      'hive_sync.db'='${importConfig.sinkDatabase}',             -- required, hive 新建的数据库名
       |      'hive_sync.mode' = 'hms',            -- required, 将hive sync mode设置为hms, 默认jdbc
       |      'hive_sync.metastore.uris' = '${ClusterConstant.HiveMeta.META_URL}' -- required, metastore的端口
       |       )
       |
       |""".stripMargin
  }


}
